Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
Mac and OpenDoc are trademarks of Apple Computer, Inc.
The Problem
When an OpenDoc document is saved, all of its open windows are externalized to the document file so that they can be recreated with the same properties (including position and size) the next time the user opens the document. However, when a document is opened, the saved window may be entirely off-screen if the montor configuration has changed. This can occur when the resolution of a monitor has been reduced, when a monitor has been removed altogether, or when the document is saved on one system and opened on a different one.
Because part editors are responsible for the creation of windows for their root frames, part developers must make sure that each window internalized from storage is opened on-screen. OpenDoc's Window Utility functions can be used by part developers to easily access a window's externalized properties. However, these utilities will not validate or alter a window's position or size. Validation can only be done by the part editor because only the part editor knows where to move an off-screen window. For example, several windows may need to be moved if a part editor requires fixed relative positioning for the windows.
The Solution
Before creating a saved window, your part editor should validate the window's position relative to the available screen region. In general, the minimum requirement is to have part of the window's drag region (title bar) on-screen. This allows the user to reposition the window and, if necessary, click on the zoom box to shrink an oversized window down to the main screen size. The following sample code is extracted from SamplePart, a basic OpenDoc part editor written by the OpenDoc sample code team. This method, GetSavedWindowProperties, uses the Window Utilities function BeginGetWindowProperties to read the saved properties of a window. It then validates the window's position, changing the boundsRect of the window properties so that the window will be visible. Callers of GetSavedWindowProperties can then use the validated window properties as parameters to the Macintosh toolbox routine NewCWindow.